﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Week15_LAB01.CaculationService;

namespace Week15_LAB01
{
    public partial class Test : System.Web.UI.Page
    {
        private CaculationService.Service1 service1 = new CaculationService.Service1();

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            txtNumber1.Text = service1.GenerateNumber();
            Thread.Sleep(100);
            txtNumber2.Text = service1.GenerateNumber();
            lblOperator.Text = service1.GenerateOperator();
        }

        protected void btnJudge_Click(object sender, EventArgs e)
        {
            string resultString = "";

            switch (lblOperator.Text)
            {
                case "+":
                    resultString = service1.Add(Convert.ToInt32(txtNumber1.Text), Convert.ToInt32(txtNumber2.Text));
                    break;
                case "-":
                    resultString = service1.Sub(Convert.ToInt32(txtNumber1.Text), Convert.ToInt32(txtNumber2.Text));
                    break;
                case "*":
                    resultString = service1.Multiply(Convert.ToInt32(txtNumber1.Text), Convert.ToInt32(txtNumber2.Text));
                    break;
                case "/":
                    resultString = service1.Divide(Convert.ToInt32(txtNumber1.Text), Convert.ToInt32(txtNumber2.Text));
                    break;
            }

            if (resultString == txtResult.Text)
            {
                lblInfo.Text = "√";
            }
            else
            {
                lblInfo.Text = "×";
            }
        }
    }
}